package GUI;

import elevatorsimulator.*;

import javax.swing.*;
import java.awt.*;
import java.util.Timer;
import java.util.TimerTask;

/**
 * Controls the operation of the entire program
 */
public class MainGUI extends JFrame {
    String MAINGUITITLE = "A1: Elevator Simulator";
    //private AdminConsoleDisplay acd;

    //Objects
    Building b = new Building();
    Elevator e = new Elevator();
    ElevatorDoor ed = new ElevatorDoor();
    ElevatorDirectionLight edl = new ElevatorDirectionLight();
    FloorElevatorDirectionLight fedl = new FloorElevatorDirectionLight();
    Floor f = new Floor();
    final WorldBuilder wb = new WorldBuilder(b, e, ed, edl, fedl, f);
    public ElevatorUI eds = new ElevatorUI(wb);
    FloorUI fd = new FloorUI(wb, eds);
    AdminConsoleDisplay acd = new AdminConsoleDisplay(wb, eds, fd);

    public static boolean stopSimFlag = true;

    private Timer timer;

    /**
     * MainGUI Constructor
     */
    public MainGUI() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setTitle(MAINGUITITLE);
    }

    /**
     * Creates the main GUI window and master panel also contains timer task
     */
    public void displayGUI() {
        //Setup window properties
        setSize(1300, 750);
        setLocation(0, 0);
        setVisible(true);

        //Panels on the window
        setLayout(new BorderLayout());
        //Admin Console Display panel creation
        add(acd, BorderLayout.WEST);
        acd.viewCreator();
        add(eds, BorderLayout.CENTER);


        timer = new Timer();
        TimerTask task = new TimerTask() {

            @Override
            public void run() {

                if (stopSimFlag == false) {
                    eds.viewRefresh();
                }
            }
        };
        timer.schedule(task, 20, 1000);

    }
}
